const router = require("koa-router")();
const ShoesModel = require("../../models/shoesList");
const {mongoList} = require("../../static/data")
router.get("/api/search",async ctx=>{
    let {name} = ctx.query;
    var res = [];
    for(let m of mongoList){
        var result = await ShoesModel(m).find(
            {
                $or : [ //多条件，数组
                    {'title' : {$regex : name,$options: '$i'}},
                    {'detailMsg.shoeName' : {$regex : name,$options: '$i'}},
                    {'detailMsg.shoeCode' : {$regex : name,$options: '$i'}}
                ]
            }
        )
        res.push(...result)
    }

    ctx.body = {
        code:200,
        res,
        msg:`请求成功!共有数据${res.length}条。`
    }
})
module.exports = router;